<!--20210304    zaq    创建vue文件-->

<template>
<!--新增组别-->
  <div>
    <el-form ref="form" v-model="form">
      <el-form-item :label="group.name" >
        <el-input v-model="form.name"
                  maxlength="10"
                  show-word-limit>
        </el-input><br>
        <span style="color: #8c939d">{{group.kGText}}</span>
      </el-form-item>
      <el-form-item>
        <el-button @click="insert(form)">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {getKindGroup_0000} from "../../api";
import {insert_13101} from "../../api";
import {ElMessage} from "element-plus";

export default {
  name: "Insert-group",
  data(){
    return{
      group:{
        code:-1,
        note:"",
        kGId:-1,
        name:"",
        kGText:"",
        kBId:-1,
        delete:0
      },
      form:{
        code:-1,
        note:"",
        gId:-1,
        name:null,
        bId:-1,
        kGId:-1,
        uId:-1,
        delete:0
      }
    }
  },
  methods:{
    // 新增分组
    insert(body){
      const _this=this
      if(body.name==null||body.name.trim()==""){
        ElMessage.error('名称不能为空，请重试');
      }else{
        insert_13101(body).then(resp=>{
          if(resp.code>0){
            _this.$message({
              type: 'success',
              message: '新增分组成功!'
            });
          }else{
            ElMessage.error('新增分组失败：' + resp.note);
          }
        }).catch(error=>{
          ElMessage.error('调用接口13101失败：' + error);
        })
      }
      _this.$parent.$parent.$parent.$parent.select()
    },
    select(){
      const _this=this
      var bKind=sessionStorage.getItem("kBId")
      var book={
        bId:-1,//账簿ID
        bName:"",//账簿名称
        bCreatedate:0,//创建时间
        bDefault:0,//默认账簿
        delete:0,
        uId:-1,
        bKind:bKind,//账簿类型
        flagGroup:false,//有无组别
        bookUpdate:false,//账簿信息修改弹框
        selectDrawer: false,//查询收支信息drawer
      }
      getKindGroup_0000(book).then(resp=>{
        if(resp.code>0){
          _this.group=resp
          _this.form.kGId=resp.kGId
        }else{
          console.log("失败："+resp.note)
        }
      }).catch(error=>{
        console.log("调用接口失败:"+error)
      })
    }
  },
  created() {
    this.select()
    this.form.uId=sessionStorage.getItem("uId")
    this.form.bId=sessionStorage.getItem("bId")
  }
}
</script>

<style scoped>

</style>